package navigation

import (
	"public_security/controllers"
	"public_security/models"
	"public_security/models/navigation"
)

// 快速导航 API
type NavigationController struct {
	controllers.BaseController
}

func (i *NavigationController) Prepare() {
	i.BasePrepare()
}

// @Title create
// @Description 创建导航
// @Param	body		body 	models.Navigation	 true		"请求参数"
// @Success 200 success
// @router /create [post]
func (i *NavigationController) Create() interface{} {
	art := new(models.Navigation)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = navigation.Create(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "创建成功")
}

// @Title update
// @Description 修改导航
// @Param	body		body 	models.Navigation	 true		"请求参数"
// @Success 200 success
// @router /update [post]
func (i *NavigationController) Update() interface{} {
	art := new(models.Navigation)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = navigation.Update(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "修改成功")
}

// @Title remove
// @Description 删除导航
// @Param	body		body 	models.Navigation	 true		"请求参数"
// @Success 200 success
// @router /remove [post]
func (i *NavigationController) Remove() interface{} {
	art := new(models.Navigation)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = navigation.Remove(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "删除成功")
}

// @Title query
// @Description 查询导航
// @Param	body		body 	models.Navigation	 true		"请求参数"
// @Success 200 {object} models.Navigation
// @router /query [post]
func (i *NavigationController) Query() interface{} {
	art := new(models.Navigation)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	results := navigation.Query(art)
	return i.ToMessageSuccess(results, "查询成功")
}
